import { getUserAddressAPI, getShopInfoAPI } from "@/api";

const state = {
	userAddress: [],
	shopInfo: {},
};

const mutations = {
	GETUserAdd(state, data) {
		state.userAddress = data;
	},
	GETShopInfo(state, data) {
		state.shopInfo = data;
	},
};

const actions = {
	async getUserAdd({ commit }) {
		const res = await getUserAddressAPI();
		if (res.code === 200) {
			commit("GETUserAdd", res.data);
		} else {
			return Promise.reject(new Error(res.code));
		}
	},

	async getShopInfo({ commit }) {
		const res = await getShopInfoAPI();
		if (res.code === 200) {
			commit("GETShopInfo", res.data);
		} else {
			return Promise.reject(new Error(res.message));
		}
	},
};
const getters = {};

export default {
	namespaced: true,
	state,
	mutations,
	actions,
	getters,
};
